home *** CD-ROM | disk | FTP | other *** search
- #!/usr/sbin/perl
- # $Id: osearch-cgi.m,v 1.5 1996/11/04 15:47:34 murphy Exp $
- #
- # osearch-cgi - CGI search engine for Oasis
- #
- # $Log: osearch-cgi.m,v $
- # Revision 1.5 1996/11/04 15:47:34 murphy
- # add DT_utilities to virtual doc root
- #
- # Revision 1.4 1996/10/29 21:28:22 murphy
- # changes necessary to support forum 96 CD
- #
- # Revision 1.3 1996/04/22 13:38:29 DTjanitor
- # change .www references to .www_6.0
- #
- # Revision 1.2 1996/02/15 22:57:02 dave
- # fixed up incorrect attempts at using ~dave
- #
- # Revision 1.1 1996/02/15 19:47:57 dave
- # adding in collapsed cgi-bin{int,ext,cd} files into their .m new forms
- #
- # Revision 1.1 1995/09/11 23:17:51 dave
- # Initial revision
- #
- # Revision 1.5 1995/03/11 01:40:27 dave
- # NOW osearch IS bossv osearch-cgi! for .html files to work for URLs (distinguishing doc from path (see bottom of file))
- #
- # Revision 1.4 1995/03/11 00:38:26 dave
- # not finished but need to check these in to test 'em at work
- #
- # Revision 1.3 1995/02/16 17:52:54 dave
- # modified to refer to cgi-lib.pl locally & added cgi-lib.pl local copy
- #
- # Revision 1.2 1995/02/15 23:23:37 dave
- # updating incorrect html syntax and robustifying the code
- #
- #
-
- require('cgi-lib.pl') || die "can\'t require cgi-lib.pl: $!";
-
- $request_method = $ENV{'REQUEST_METHOD'};
- $query_string = $ENV{'QUERY_STRING'};
- $path_info = $ENV{'PATH_INFO'};
- $path_info =~ s/^\///; $path_info =~ s/\// /;
- $content_length = $ENV{'CONTENT_LENGTH'};
-
- #####################################
- # Setup/Define Machine-Specific stuff
- #
- # DEFINE THE SERVER NAME FOR THE oksvr RUN OUT OF /etc/init.d/okserver:
-
- chop($server=`hostname`);
-
- #get user home directory from this file evaluates $userHome
- eval (`cat "/tmp/.userhome_$ENV{'SERVER_PORT'}"`);
-
- # get location of CDROM mount point evaluates $cdromMount
- eval (`cat "/tmp/.cdlocation_$ENV{'SERVER_PORT'}"`);
-
-
- # DEFINE WHAT THE FULSEARCH PATH WILL BE SO WE CAN BUILD THE URLs:
- #
- # Make sure the value of the $OksvrSearchRoot variable inside the
- # /usr/people/dave/.DT_OksvrRoot file, specified below, is equivalent
- # to what the OKSVR_ROOT variable is defined to be inside the
- # /etc/init.d/okserver script
- # AND have it's path from the root directory of "/" be whatever makes
- # sense for you on your server machine--we originally put it in
- # /usr/tmp but this became unreliable since /usr/tmp/ IS "fair game"
- # for being completely cleaned out at any time.
- # For example, if /etc/init.d/okserver has defined:
- # OKSVR_ROOT=/usr/local/www/toolbox/searchtools
- # then the /usr/people/dave/.DT_OksvrRoot file should consist of the
- # following (starting from and including the `$' (dollar) sign:
- # $OksvrSearchRoot="/usr/local/www/toolbox/searchtools" ;
- #
- $DocumentRoot="$ENV{'DOCUMENT_ROOT'}/toolbox/searchtools";
- chop($OasisCmdPort = `cat "$ENV{'DOCUMENT_ROOT'}/../logs/oksrv.port"`);
- $DT_utilities="$ENV{'DOCUMENT_ROOT'}/../DT_utilities";
-
- $OksvrSearchRoot = "$OksvrSearchRoot/toolbox/all" ;
-
-
- ########################################
- # Print standard document header
- # title - document title (will also appear as H1 text)
- # titleimg - if used, will display instead of H1 title (title will be
- # ALT= text)
- sub header {
- local ($title,$titleimg) = @_;
-
- print &PrintHeader;
- print "<HTML>\n";
- print "<HEAD>\n";
- print "<TITLE>$title</TITLE>\n";
- print "<LINK rev=\"made\" href=\"mailto:DTjanitor\@sgi.com\">\n";
- print "</HEAD>\n\n";
-
- print "<BODY>\n";
- print "<H1>";
- if ($titleimg) {
- print "<img align=\"center\" src=\"$titleimg\"><img src=\"/toolbox/www/images/space40.gif\">$title";
- } else {
- print "$title";
- }
- print "</H1>\n";
- print "<h3><a href=\"/toolbox/DT.html\">HUB</a> | <a href=\"/toolbox/www/cgi-bin/pheedbak-cgi/toolbox/www/cgi-bin/?osearch-cgi\">Pheedbak</a> | <a href=\"/toolbox/DTtree.html\">Tree</a> | <a href=\"/toolbox/DTtopic.html\">Topic</a> | <a href=\"/toolbox/DTalfabetic.html\">A-Z</a> | <a href=\"/toolbox/DThot.html\">Hot</a> | <a href=\"/toolbox/DTnew.html\">New</a><img src=\"/toolbox/www/images/space90.gif\"><img align=\"middle\" alt=\"Silicon Graphics, Inc.\" src = \"/toolbox/www/images/sgilogosm.gif\"></h3>";
- print "<HR size=\"4\">\n";
- }
-
- ########################################
- # Print standard document footer
- # The following hidden variables may be imbedded in the form:
- # back_url - URL back to form
- # back_url_image - Image for back link
- # back_url_label - Label for back link (will be ALT= text if image)
- # return_url - URL to return to document
- # return_url_image - Image for return link
- # return_url_label - Label for return link (will be ALT= text if image)
- # This will also print any icons for areas specified in PATH_INFO.
- sub footer {
- if ($in{'back_url'}) {
- if ($in{'back_url_image'}) {
- print "<BR><A HREF=\"$in{'back_url'}\"><IMG SRC=\"$in{'back_url_image'}\" ALT=\"\">$in{'back_url_label'}</A>\n";
- } else {
- print "<BR><A HREF=\"$in{'back_url'}\"><B>$in{'back_url_label'}</B></A>\n";
- }
- }
- if ($in{'return_url'}) {
- if ($in{'return_url_image'}) {
- print "<BR><A HREF=\"$in{'return_url'}\"><IMG SRC=\"$in{'return_url_image'}\" ALT=\"\">$in{'return_url_label'}</A>\n";
- } else {
- print "<BR><A HREF=\"$in{'return_url'}\"><B>$in{'return_url_label'}</B></A>\n";
- }
- }
- print "<BR>\n";
- print "<hr size=\"4\">\n";
- print "<p><FONT SIZE=\"-1\">DT pheedbak and comments are <i>always</i> \n";
- print "appreciated by\n";
- print "<A HREF=\"/toolbox/www/cgi-bin/pheedbak-cgi/toolbox/www/cgi-bin?DTsearch-cgi\">DTjanitor\@.sgi.com</A>. </FONT>\n";
- print "<P>\n";
-
- print "<A HREF=\"/toolbox/sgi_info.html\"><FONT SIZE=\"-3\">Copyright © 1995, Silicon Graphics, Inc.</FONT></A>\n";
- print "</BODY>\n";
- print "</HTML>\n";
- }
-
- #######################################################
- # Remove duplicate documents from oasiscmd query output
- sub remove_dups {
- local(@oasis) = @_;
- local($ptr,$title,$type,$path,$url,@noasis);
-
- foreach $_ (@oasis) {
- ($ptr,$title,$type,$path) = (/^(\d+)\.\s+(.*)\s+(\d+)\s*(\S*)$/);
- $url = $path;
- $url =~ s/$OksvrSearchRoot\/[^\/]+\/toolbox//;
- next if ($title{$url} eq $title);
- $title{$url} = $title;
- $ptr{$url} = $ptr;
- $type{$url} = $type;
- }
- foreach $url (sort keys(%title)) {
- push(@noasis,"$ptr{$url}. $title{$url} $type{$url} $url");
- }
- @noasis;
- }
-
- &ReadParse(); # Get output from form
-
- ##########################################################################
- # Generate an error if no keywords or doctitle and if no sub-database name
- unless (($in{'keywords'} || $in{'doctitle'}) && $in{'subset'}) {
- &header("DT Search error!","/toolbox/www/images/OasisIII_icon.gif");
- unless ($in{'keywords'} || $in{'doctitle'}) {
- print "<h2>You must specify search criteria!</H2>\n";
- } elsif (! $in{'subset'}) {
- print "<h2>You must specify an area to search!</H2>\n";
- }
- &footer;
- exit 1;
- }
- # (else) go with the "successful" header
- &header("DT Search Results...","/toolbox/www/images/OasisIII_icon.gif");
-
-
- ######################################################
- # Setup the oasiscmd command line from the form output
- #
- #$command = "$cdromMount/bin/oasiscmd -p $OasisCmdPort ";
- $command = "$DT_utilities/oasiscmd -p $OasisCmdPort ";
- $command .= "-server $server -db \"toolbox\" -subset \"";
- ($subset = $in{'subset'}) =~ s/\\0/\;/g;
- $command = $command . $subset . "\"";
-
- $command = $command . " -kywd \"$in{'keywords'}\"" if ($in{'keywords'});
- $command = $command . " -title \"$in{'doctitle'}\"" if ($in{'doctitle'} && !$in{'keywords'});
- $command = $command . " -fname \"$in{'filename'}\"" if ($in{'filename'});
- $command = $command . " -after \"$in{'after'}\"" if ($in{'after'});
- $command = $command . " -before \"$in{'before'}\"" if ($in{'before'});
-
-
- ###################################################
- # Run oasiscmd, and pipe output to OASIS filehandle
- print "<PRE><BR>Output of: $command\n</PRE>\n" if ($in{'debug'});
- open(OASIS, "-|") || exec ($command);
- @oasis = <OASIS>;
- close(OASIS);
-
-
- #####################################################
- # Special subroutine to sort output by title and path
- sub sort_oasis {
- local($doca,$docb);
- local($patha,$pathb);
-
- ($doca,$patha) = ($a =~ /\d+\.\s+(.*)\s+\d+\s*(\S*)$/);
- ($docb,$pathb) = ($b =~ /\d+\.\s+(.*)\s+\d+\s*(\S*)$/);
-
- if ($doca eq $docb) {
- $patha cmp $pathb;
- } else {
- $doca cmp $docb;
- }
- }
-
- if ($oasis[0] =~ /No Items Found/ ) {
- # If no results...
- print "<B>No documents found matching search criteria.</B><P>\n";
- print "<BR>$oasis[0]\n<P>\n" if ($in{'debug'});
- } elsif ($oasis[1] =~ /Usage:/ || $#oasis < 0) {
- # Server error
- print "<P><B>The oksvr document search engine is not responding.</B><BR>\n";
- print "<P>Please consult the <a href=\"../../sifttree.html\">OasisIII \n";
- print "Search Tool Operability Issues</a> document for an \n";
- print "explanation of how to [re-]activate the oksvr server program.<P>\n";
- print "<BR>$oasis[1]\n<P>\n" if ($in{'debug'} && $oasis[1]);
- } else {
- # It worked, generate search output
- ($pid) = ($oasis[0] =~ /^0\.\s+(\d+)/); # Get oasiscmd pid
- shift(@oasis) if ($pid);
- print "<PRE>oasiscmd pid = $pid\n<BR></PRE>\n" if ($in{'debug'});
- @oasis = &remove_dups(@oasis);
- $count = $#oasis + 1;
- print "Search located $count document";
- print "s" if ($count > 1);
- print "<BR>\n";
- print "Note: documents ending in <code>.html</code> show up with their";
- print " title instead of their path+filename.<br>\n" ;
- print "<B>Select the document you wish to view:</B>\n";
-
- print "<MENU>\n";
- foreach $_ (sort sort_oasis @oasis) {
- ($ptr,$doc,$type,$path) = (/(\d+)\.\s+(.*)\s+(\d+)\s+(\S+)/);
-
- print "<br>ptr=`",$ptr,"'; doc=`",$doc,"'; type=`",$type,"'; path=`",$path,"'<br>" if ($in{'debug'});
-
- # doc will equal path+filename UNLESS "$doc ends in .html
- # if this is the case the string inside <title>...</title>
- # is what gets assigned to the $doc field. when doc IS a
- # .html file, the following substitution properly fails.
- if ($doc =~ s/^all\/cd\d+\///) {
- undef;
- } else {
- $doc =~ s/^all\///;
- }
-
- # strip off $OksvrSearchRoot from the absolute path and replace
- # this with "/toolbox" so links for "path" are properly
- # defined for the http server to understand. this all occurs
- # within the actual realm of the /toolbox/searchtools/toolbox/all
- # subtree, which consists entirely of links back up to the actual
- # TOP-OF-TREE (HUB) under /toolbox; this searchtools/toolbox/all
- # directory of links is what the Fulcrum oksvr index files in
- # /toolbox/searchtools/toolbox/toolbox.* uses to simulate the
- # top-of-tree used to complete file retrieval when doing searches
- # inside OasisIII.
-
- if ($path =~ s/.*\/toolbox\/searchtools\/toolbox\/all\///) {
- if ($path =~ s/^(cd\d+)\///) {
- $cur_cd = $1;
- } else {
- undef $cur_cd;
- }
- $path = "/toolbox/$path";
- }
-
- if (! $path) {
- ($ptr,$doc,$type,$path) = (/(\d+)\.\s+(.*)\s+(\d+)\s*(\/*\S*)$/);
- print "<LI><A HREF=\"/toolbox/www/cgi-bin/oretrieve-cgi?$ptr\">$doc</A>\n";
- } else {
- # If the document is local, generate a URL rather than a call
- # to oasiscmd to retrieve the document
- print "<LI><A HREF=\"$path\">$doc</A>\n";
- }
- }
- print "</MENU>\n";
- }
-
- &footer;
-
-